home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-01 / owldlgs.zip / DLGALL.CPP < prev    next >
C/C++ Source or Header  |  1993-04-08  |  7KB  |  163 lines

  1. /**********************************************************************/
  2. /*                  Dlgall.cpp by Bob Bourbonnais                     */
  3. /*              released to the public domain 1/10/92                 */
  4. /*     This program demonstrates using dialog boxs for everything.    */
  5. /*       It is a summation of the other owl dialog box examples.      */
  6. /*           This example has a dialog box as the main window.        */
  7. /*     The main window dialog box can activate other dialog boxes     */
  8. /*               either from the menu or from buttons.                */
  9. /*      It can activate Modal, System Modal, Message Box, non-modal   */
  10. /*       with parent and non-modal without parent dialog boxes.       */
  11. /**********************************************************************/
  12. #include <owl.h>
  13. #include <dialog.h>
  14. #include "dlgall.h"
  15.  
  16. class TDialogAllDialog : public TDialog    // Dialog class to add
  17.   {                     // processing for menu and
  18.   public:                 // button selections
  19.     TDialogAllDialog(LPSTR lpName)         // constructor calls
  20.       :TDialog(NULL,lpName) {};         // base class constructor
  21.     virtual void HandleModalMenu(RTMessage Msg)      // menu handler
  22.       = [CM_FIRST + IDM_MODAL_DIALOG];
  23.     virtual void HandleMenuOK(RTMessage Msg)
  24.       = [CM_FIRST + IDM_MB_OK];
  25.     virtual void HandleSysModalMenu(RTMessage Msg)
  26.       = [CM_FIRST + IDM_SYS_MODAL];
  27.     virtual void HandleNonModalMenu(RTMessage Msg)
  28.       = [CM_FIRST + IDM_NON_MODAL_DIALOG];
  29.     virtual void HandleNoParentMenu(RTMessage Msg)
  30.       = [CM_FIRST + IDM_NO_PARENT_NON_MODAL];
  31.  
  32.     virtual void HandleModalButton(RTMessage Msg) // button handler
  33.       = [ID_FIRST + IDB_MODAL_DIALOG];
  34.     virtual void HandleButtonOK(RTMessage Msg)
  35.       = [ID_FIRST + IDB_MB_OK];
  36.     virtual void HandleSysModalButton(RTMessage Msg)
  37.       = [ID_FIRST + IDB_SYS_MODAL];
  38.     virtual void HandleNonModalButton(RTMessage Msg)
  39.       = [ID_FIRST + IDB_NON_MODAL_DIALOG];
  40.     virtual void HandleNoParentButton(RTMessage Msg)
  41.       = [ID_FIRST + IDB_NO_PARENT_NON_MODAL];
  42.  
  43.     void DisplayStatus(int nStatus); // display status of buttons pressed
  44.                      // when within message boxes
  45.   };
  46.  
  47. void TDialogAllDialog:: HandleModalMenu(RTMessage)
  48.   {
  49.   GetApplication()->ExecDialog(new TDialog(this,"Modal_Dialog_Box"));
  50.   }               //ExecDialog activates a modal dialog box
  51. void TDialogAllDialog:: HandleMenuOK(RTMessage)
  52.   {
  53.   int nStatus;
  54.   nStatus = MessageBox(HWindow,"Message inside of Message Box",
  55.                "Title of Message Box",MB_OK);
  56.   DisplayStatus(nStatus);
  57.   }
  58. void TDialogAllDialog:: HandleSysModalMenu(RTMessage)
  59.   {
  60.   GetApplication()->ExecDialog(new TDialog(this,"Sys_Modal_Dialog_Box"));
  61.   }               //ExecDialog activates a modal dialog box
  62.  void TDialogAllDialog:: HandleNonModalMenu(RTMessage)
  63.   {
  64.   GetApplication()->MakeWindow(new TDialog(this,"Non_Modal_Dialog_Box"));
  65.   }               //MakeWindow activates a non-modal dialog box with parent
  66. void TDialogAllDialog:: HandleNoParentMenu(RTMessage)
  67.   {
  68.   GetApplication()->MakeWindow(new TDialog(NULL,"No_Parent_Non_Modal"));
  69.   }               // MakeWindow activates a non-modal dialog box
  70.           // the null qualifier makes it parentless.
  71.  
  72. void TDialogAllDialog:: HandleModalButton(RTMessage)
  73.   {
  74.   GetApplication()->ExecDialog(new TDialog(this,"Modal_Dialog_Box"));
  75.   }
  76. void TDialogAllDialog:: HandleButtonOK(RTMessage)
  77.   {
  78.   int nStatus;
  79.   nStatus = MessageBox(HWindow,"Message inside of Message Box",
  80.                "Title of Message Box",MB_OK);
  81.   DisplayStatus(nStatus);
  82.   }
  83. void TDialogAllDialog:: HandleSysModalButton(RTMessage)
  84.   {
  85.   GetApplication()->ExecDialog(new TDialog(this,"Sys_Modal_Dialog_Box"));
  86.   }
  87. void TDialogAllDialog:: HandleNonModalButton(RTMessage)
  88.   {
  89.   GetApplication()->MakeWindow(new TDialog(this,"Non_Modal_Dialog_Box"));
  90.   }
  91. void TDialogAllDialog:: HandleNoParentButton(RTMessage)
  92.   {
  93.   GetApplication()->MakeWindow(new TDialog(NULL,"No_Parent_Non_Modal"));
  94.   }
  95.  
  96. void TDialogAllDialog::DisplayStatus(int nStatus)
  97.   {
  98.   char szBuffer[40];
  99.   switch (nStatus)
  100.     {
  101.     case IDABORT:
  102.       wsprintf(szBuffer,"The Abort Button sent number %d",nStatus);
  103.       break;
  104.     case IDCANCEL:
  105.       wsprintf(szBuffer,"The Cancel Button sent number %d",nStatus);
  106.       break;
  107.     case IDIGNORE:
  108.       wsprintf(szBuffer,"The Ignore Button sent number %d",nStatus);
  109.       break;
  110.     case IDNO:
  111.       wsprintf(szBuffer,"The No Button sent number %d",nStatus);
  112.       break;
  113.     case IDOK:
  114.       wsprintf(szBuffer,"The OK Button sent number %d",nStatus);
  115.       break;
  116.     case IDRETRY:
  117.       wsprintf(szBuffer,"The Retry Button sent number %d",nStatus);
  118.       break;
  119.     case IDYES:
  120.       wsprintf(szBuffer,"The Yes Button sent number %d",nStatus);
  121.       break;
  122.     default:
  123.       wsprintf(szBuffer,"Out of Range Value  %d Passed",nStatus);
  124.     }
  125.     int i;
  126.     if (nStatus > 0)
  127.        MessageBox(HWindow,szBuffer,"Button Message",MB_OK);
  128.     else           //not enough memory to create message box
  129.        for (i=0;i<100;i++)MessageBeep(0);     // so beep instead
  130.   }
  131.  
  132.  
  133. class TDialogAllApp : public TApplication  // Application Class to contain
  134.   {                                      // the application
  135.   public:
  136.     TDialogAllApp(LPSTR lpName, HANDLE hInstance,  // constructor calls the
  137.         HANDLE hPrevInstance,            // base class constructor
  138.         LPSTR lpCmdLine, int nCmdShow)
  139.         :TApplication(lpName, hInstance,
  140.                   hPrevInstance,
  141.                   lpCmdLine, nCmdShow) {};
  142.  
  143.     virtual void InitMainWindow(); // overrides base class InitMainWindow
  144.   };
  145.  
  146. void TDialogAllApp::InitMainWindow() // to initialize a dialog box
  147.   {                                // as the main window
  148.   MainWindow = new TDialogAllDialog("Main_Window_Dialog");
  149.   }                                // using message processing provided
  150.                    // by derived class
  151.  
  152. int PASCAL WinMain(HANDLE hInstance,              // main entry point from
  153.            HANDLE hPrevInstance,          // windows to this program
  154.            LPSTR lpCmdLine , int nCmdShow)
  155.   {
  156.   TDialogAllApp DialogAll("Dialog Tester",hInstance,  // create instance of
  157.                hPrevInstance,             // the dialog application
  158.                lpCmdLine,nCmdShow);
  159.   DialogAll.Run();                                  // run it
  160.   return (DialogAll.Status);                        // exit
  161.   }
  162. /**********************************************************************/
  163.